package users

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"product/authorization/serve/internal/svc"
	"product/authorization/serve/internal/types"
)

type DeleteUsersLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// NewDeleteUsersLogic delete users
func NewDeleteUsersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteUsersLogic {
	return &DeleteUsersLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeleteUsersLogic) DeleteUsers(req *types.DeleteUserReq) (resp *types.DeleteUserResp, err error) {
	if req.ID <= 0 {
		return &types.DeleteUserResp{
			Message: "请求选择删除的用户",
			Ok:      false,
		}, nil
	}
	err = l.svcCtx.UsersModel.Delete(l.ctx, req.ID)
	if err != nil {
		return &types.DeleteUserResp{
			Message: "删除用户失败",
			Ok:      false,
		}, nil
	}
	return &types.DeleteUserResp{
		Message: "删除用户成功",
		Ok:      true,
	}, nil
}
